/*
 * MetNum.cpp
 *
 *  Created on: 11/08/2013
 *      Author: jose
 */

#include "MetNum.h"
#include <iostream>
using namespace std;

void MetNum::GaussSeidel(Malla* m, int n_it, double p, EcDiff Ec, int n_mallas){
	it=0;
	if(m->Nivel()==n_mallas-1){
		do{

			Emax=0;
			for (int i=0; i<m->Size_i(); i++){
				for(int j=0;j<m->Size_j();j++){
					if(m->D(i,j)==0){
						Vant=m->V(i,j);
						m->Set_V(i,j,Ec.Get_V(m,i,j));
						Eant=abs(Vant-m->V(i,j));
						if(Eant>Emax)
							Emax=Eant;
					}
				}
			}
			it++;
		}while((n_it>it)&&(Emax>p));
		//
	}else{
		do{
			Emax=0;
			for (int i=0; i<m->Size_i(); i++){
				for(int j=0;j<m->Size_j();j++){
					if(m->D(i,j)==0){
						Vant=m->V(i,j);
						m->Set_V(i,j,Ec.Get_E(m,i,j));
						Eant=abs(Vant-m->V(i,j));
						if(Eant>Emax)
							Emax=Eant;
					}
				}
			}
			it++;
		}while((n_it>it)&&(Emax>p));

	}
}
